import {request} from "@/utils/service"

export type RowMeta = {
  id: number;
  customerID: number;
  envVersion: number;
  cve: string;
  bugLevel: number;
  status: number;
  app: string;
  discoverVersion: string;
  feedback: string;
  fixVersion: string;
  fixer: string;
  bugDesc: string;
  verifyInfo: string;
  fixSuggest: string;
  comment: string;
  attachmentID: number;
  tags: string;
  /** vxe-table 自动添加上去的属性 */
  _VXE_ID?: string;
};

export type BugfixResponseData = RowMeta & {
  updatedAt: string;
};


export type BugfixTableData = ApiResponseData<{
  list: BugfixResponseData[]
  total: number
}>

interface searchParams {
  /** 当前页码 */
  currentPage: number
  /** 查询条数 */
  size: number
  name?: string
  cve?: string
  app?: number
  bugLevel?: number
}

interface switchStatus {
  id: number | string
  ids: string
  status: number | string
  version: string
  fixer: number | string
}

interface batchDeleteBug {
  ids: string
}

// 添加bug
export function addBugApi(data: RowMeta) {
  return request<ApiResponseData<null>>({
    url: "/customer/bug",
    method: "post",
    data
  })
}

// 编辑漏洞
export function updateBugApi(data: RowMeta) {
  return request<ApiResponseData<BugfixResponseData>>({
    url: "/customer/bug",
    method: "put",
    data
  })
}

// 切换漏洞状态
export function switchBugStatusApi(data: switchStatus) {
  return request<ApiResponseData<BugfixResponseData>>({
    url: "/customer/bugStatus",
    method: "put",
    data
  })
}

// 获取漏洞
export function getBugApi(params: searchParams) {
  return request<BugfixTableData>({
    url: "/customer/bug",
    method: "get",
    params
  })
}

/** 删 */
export function deleteBugApi(id: number) {
  return request({
    url: `customer/bug/${id}`,
    method: "delete"
  })
}

/** 批量上传 */
export function batchImportBug(data = {}) {
  return request({
    url: "/customer/bug/batch",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  })
}

/** 批量删除漏洞 */
export function batchDeleteBugApi(data: batchDeleteBug) {
  return request<ApiResponseData<BugfixResponseData>>({
    url: "/customer/bug/batch",
    method: "delete",
    data
  })
}
